/**
 * Created by xxcao on 2017/6/9.
 */


var express = require('express');
var router = express.Router();
var util = require('../util/util');
var taskDao = require('../dao/taskDao');

//创建任务(激活)
router.post('/create', function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/create', 'POST', req.body);
        taskDao.create(req, res, next);
    }
});

//获取看板下的任务
router.get('/getTasks', function(req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/getTasks', 'GET', req.query);
        taskDao.get(req, res, next);
    }
});

//删除任务
router.put('/delete', function(req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/delete', 'PUT', req.body);
        taskDao.delete(req, res, next);
    }
});

//任务状态变更
router.put('/status', function (req, res,  next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/status', 'PUT', req.body);
        taskDao.changeStatus(req, res, next);
    }
});

//领取任务
router.put('/receive', function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/receive', 'PUT', req.body);
        taskDao.receive(req, res, next);
    }
});

//任务归档
router.post('/archive', function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        //任务归档
        util.logInfo(0, 'task/archive', 'POST', req.body);
        taskDao.archive(req, res, next);
    }
});

//更新任务
router.put('/update', function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/update', 'PUT', req.body);
        taskDao.update(req, res, next);
    }
});

//添加批注
router.post('/comment', function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/comment', 'POST', req.body);
        taskDao.addComment(req, res, next);
    }
});

//获取归档列表
router.get('/archives', function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/archives', 'GET', req.query);
        taskDao.archives(req, res, next);
    }
});

//获取归档详情
router.get('/archiveTasks', function (req, res, next) {
    if(util.removeFavicon(req,res)) {
        util.logInfo(0, 'task/archiveTasks', 'GET', req.query);
        taskDao.archiveTasks(req, res, next);
    }
});

module.exports = router;

